package com.ruoyi.project.pms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.pms.domain.PmsGoodsAttribute;
import com.ruoyi.db.pms.domain.query.PmsGoodsAttributeQueryVo;
import com.ruoyi.project.pms.service.PmsGoodsAttributeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品参数Controller
 *
 * @author ruoyi
 * @date 2020-04-21
 */
@Api(tags="pms管理：商品参数管理")
@RestController
@RequestMapping("/pms/attribute")
public class PmsGoodsAttributeController extends BaseController
{
    @Autowired
    private PmsGoodsAttributeService pmsGoodsAttributeService;

    @ApiOperation("查询商品参数列表")
    @PreAuthorize("@ss.hasPermi('pms:attribute:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsGoodsAttributeQueryVo pmsGoodsAttributeQueryVo)
    {
        startPage();
        List<PmsGoodsAttribute> list = pmsGoodsAttributeService.selectPmsGoodsAttributeList(pmsGoodsAttributeQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出商品参数列表")
    @Log(title = "商品参数", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('pms:attribute:export')")
    @GetMapping("/export")
    public AjaxResult export(PmsGoodsAttributeQueryVo pmsGoodsAttributeQueryVo)
    {
        List<PmsGoodsAttribute> list = pmsGoodsAttributeService.selectPmsGoodsAttributeList(pmsGoodsAttributeQueryVo);
        ExcelUtil<PmsGoodsAttribute> util = new ExcelUtil<PmsGoodsAttribute>(PmsGoodsAttribute.class);
        return util.exportExcel(list, "attribute");
    }

    /**
     * @author 张涛
     * @return
     */
    @ApiOperation("根据Id获取某个商品的所有参数信息")
    @Log(title = "商品参数", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:attribute:query')")
    @GetMapping(value = "/getAttributeById/{aid}")
    public TableDataInfo getAttributeById(@PathVariable("aid") Long aid)
    {
        List<PmsGoodsAttribute> list = (List<PmsGoodsAttribute>) pmsGoodsAttributeService.selectPmsGoodsAllAttributeById(aid);
        return getDataTable(list);
    }

    /**
     * @author 张涛
     * @return
     */
    @ApiOperation("修改商品参数数组")
    @PreAuthorize("@ss.hasPermi('pms:attribute:updateAttributeList')")
    @RequestMapping(value ="/updateAttributeList",method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult updateAttributeList(@RequestBody List<PmsGoodsAttribute> list)
    {
        return toAjax(pmsGoodsAttributeService.updatePmsGoodsAttributeList(list));
    }

    @ApiOperation("获取商品参数详细信息")
    @Log(title = "商品参数", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:attribute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsGoodsAttributeService.selectPmsGoodsAttributeById(id));
    }

    @ApiOperation("新增商品参数")
    @Log(title = "商品参数", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('pms:attribute:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PmsGoodsAttribute pmsGoodsAttribute)
    {
        return toAjax(pmsGoodsAttributeService.insertPmsGoodsAttribute(pmsGoodsAttribute));
    }

    @ApiOperation("修改商品参数")
    @Log(title = "商品参数", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('pms:attribute:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PmsGoodsAttribute pmsGoodsAttribute)
    {
        return toAjax(pmsGoodsAttributeService.updatePmsGoodsAttribute(pmsGoodsAttribute));
    }

    @ApiOperation("删除商品参数")
    @Log(title = "商品参数", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('pms:attribute:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsGoodsAttributeService.deletePmsGoodsAttributeByIds(ids));
    }
}
